package api

import (
	"fmt"
)

var (
	Name    string
	SurName string
)

// Teacher 定义结构体
type Teacher struct {
	Name   string
	Age    int
	School string
}

func init() {
	fmt.Println("加载了api目录的init方法1")
}

func InstanceApi() string {
	Name = "chen"
	SurName = "venki"

	return SurName + "." + Name
}

// AccessApiOne 入口
func AccessApiOne() {
	// 创建结构体方式1
	var t1 Teacher
	t1.Name = "venki.chen"
	t1.Age = 28
	t1.School = "广西科技大学"
	fmt.Println(t1)
	fmt.Println("----------------------")

	// 创建结构体方式2
	var t2 Teacher = Teacher{}
	t2.Name = "cwxc"
	t2.Age = 28
	t2.School = "广西科技大学"
	fmt.Println(t2)
	fmt.Println("--------------------------")

	// 创建结构体方式3 返回结构体指针
	var t3 *Teacher = new(Teacher)
	/*(*t3).Name = "slp"
	(*t3).Age = 26
	(*t3).School = "福建师范大学"*/
	/*之所以(*t3).Name 和t3.Name可以互用是因为go底层对此种定义进行了取值运算，会将t3.Name转换为(*t3).Name*/
	t3.Name = "slp"
	t3.Age = 18
	t3.School = "福建师范大学"
	fmt.Println(*t3)
	fmt.Println("--------------------------")

	// 创建结构体方式4 返回结构体指针
	var t4 *Teacher = &Teacher{}
	/*(*t4).Name = "slp"
	(*t4).Age = 26
	(*t4).School = "福建师范大学"*/
	/*之所以(*t4).Name 和t4.Name可以互用是因为go底层对此种定义进行了取值运算，会将t4.Name转换为(*t4).Name*/
	t4.Name = "slp"
	t4.Age = 26
	t4.School = "福建师范大学"
	fmt.Println(*t4)
	fmt.Println("--------------------------")
}

func AccessApiTwo() {

}
